//
//  ALTabBarController.m
//  Ummy.G
//
//  Created by 安林 on 16/9/25.
//  Copyright © 2016年 安林. All rights reserved.
//

#import "ALTabBarController.h"


@interface ALTabBarController ()

@end

@implementation ALTabBarController

- (void)viewWillAppear:(BOOL)animated{

    //先调用一下父类的控制器
    [super viewWillAppear:animated];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    //首页
    ALHomeViewController *home = [[ALHomeViewController alloc]init];
    [self addChildController:home andTitle:@"首页" andImage:@"icon_tabbar_homepage-1" andSelectImage:@"icon_tabbar_homepage_selected-1"];


    
    
    //商家
    ALShopsViewController *shops = [[ALShopsViewController alloc]init];
    [self addChildController:shops andTitle:@"商家" andImage:@"icon_tabbar_merchant_normal" andSelectImage:@"icon_tabbar_merchant_selected"];
    
    
    //我的
    ALMineViewController *mine = [[ALMineViewController alloc]init];
    [self addChildController:mine andTitle:@"我的" andImage:@"icon_tabbar_mine" andSelectImage:@"icon_tabbar_mine_selected"];
}


#pragma mark 提取相同部分
- (void)addChildController:(UIViewController *)viewController andTitle:(NSString *)title andImage:(NSString *)image andSelectImage:(NSString *)selectImage{
    
    ALNavigationController *na = [[ALNavigationController alloc]initWithRootViewController:viewController];
    na.tabBarItem.title = title;
    
    
    //设置文本属性 可以设置文字的颜色 大小
    // 设置成可变的字典
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = [UIColor blackColor];
    
    [na.tabBarItem setTitleTextAttributes:attrs forState:UIControlStateSelected];
    
    // 字体大小只能在默认状态下设置
    NSMutableDictionary *attrF = [NSMutableDictionary dictionary];
    attrF[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    
    [na.tabBarItem setTitleTextAttributes:attrF forState:UIControlStateNormal];
    
    
    //没有选中状态
    na.tabBarItem.image = [UIImage imageNamed:image];
    
    
    //禁止渲染--(前面建了一个分类，下次用的时候可以直接用了，专门给系统的类写方法)
    UIImage *imageNew = [UIImage imageRender:selectImage];
    
    
    //选中状态
    na.tabBarItem.selectedImage = imageNew;
    [self addChildViewController:na];

}



@end
